package com.whmnx.my.ui.viewmodel;

import android.app.Application;
import android.os.Bundle;

import androidx.annotation.NonNull;

import com.afollestad.materialdialogs.DialogAction;
import com.afollestad.materialdialogs.MaterialDialog;
import com.alibaba.android.arouter.launcher.ARouter;
import com.tencent.qcloud.ugckit.utils.ToastUtil;
import com.whmnx.base.constants.Constants;
import com.whmnx.base.contract._Login;
import com.whmnx.base.router.RouterActivityPath;
import com.whmnx.base.utils.MaterialDialogUtils;
import com.whmnx.my.ui.fragment.AboutFragment;
import com.whmnx.my.ui.fragment.AboutFragment2;
import com.whmnx.my.ui.fragment.InsideTradingFragment;
import com.whmnx.my.ui.fragment.MySettingFragment;
import com.whmnx.my.ui.fragment.SetLoginPassWordFragment;

import me.goldze.mvvmhabit.binding.command.BindingAction;
import me.goldze.mvvmhabit.binding.command.BindingCommand;
import me.goldze.mvvmhabit.bus.RxBus;
import me.goldze.mvvmhabit.utils.SPUtils;

/**
 * author : huang
 * date   : 2020/9/15 0015 10:18
 * version: 1.0
 */
public class SetModel extends ToolbarViewModel {
    private MySettingFragment mContext;
    public SetModel(@NonNull Application application) {
        super(application);
    }

    public void initToolbar(MySettingFragment mySettingFragment) {
        setTitleText("设置");
        this.mContext = mySettingFragment;

    }


    public BindingCommand setLogPassWordOnClickCommand = new BindingCommand(new BindingAction() {
        @Override
        public void call() {
            Bundle bundle = new Bundle();
            bundle.putInt("type",0);
            startContainerActivity(SetLoginPassWordFragment.class.getCanonicalName(),bundle);
        }
    });
    public BindingCommand setPayPassWordOnClickCommand = new BindingCommand(new BindingAction() {
        @Override
        public void call() {
            Bundle bundle = new Bundle();
            bundle.putInt("type",1);
            startContainerActivity(SetLoginPassWordFragment.class.getCanonicalName(),bundle);
        }
    });
    public BindingCommand aboutPassWordOnClickCommand = new BindingCommand(new BindingAction() {
        @Override
        public void call() {
            Bundle bundle = new Bundle();
            bundle.putInt("code",1);
            startActivity(AboutFragment2.class,bundle);
        }
    });
    public BindingCommand guanPassWordOnClickCommand = new BindingCommand(new BindingAction() {
        @Override
        public void call() {
            startContainerActivity(AboutFragment.class.getCanonicalName());
        }
    });
    public BindingCommand youPassWordOnClickCommand = new BindingCommand(new BindingAction() {
        @Override
        public void call() {
            int lv = SPUtils.getInstance().getInt(Constants.LV);
            if (lv != 2){
                ToastUtil.toastShortMessage("请先去V2认证");
                return;
            }
            startContainerActivity(InsideTradingFragment.class.getCanonicalName());
        }
    });
    /**
     * 退出
     */
    public BindingCommand logOutOnClickCommand = new BindingCommand(new BindingAction() {
        @Override
        public void call() {
            MaterialDialogUtils.showBasicDialogNoTitle(mContext.getActivity(),  "确定退出登录?")
                   .onPositive(new MaterialDialog.SingleButtonCallback() {
                @Override
                public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                    ARouter.getInstance().build(RouterActivityPath.Sign.PAGER_LOGIN).navigation();
                    SPUtils.getInstance().put(Constants.LOGIN2, false);
                     _Login  _login = new _Login();
                    //采用ARouter+RxBus实现组件间通信
                    RxBus.getDefault().post(_login);
                    finish();
                }
            }).show();
        }
    });
}
